package com.servlet;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.javabean.AddDevice;
import com.javabean.*;
/**
 * Servlet implementation class AddNewDevice
 */
@WebServlet("/files/AddNewDevice")
public class AddNewDevice extends HttpServlet {
	int userId;
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	
	public AddNewDevice() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String type = request.getParameter("devname");
		String devserial = request.getParameter("devserial");
		int serial = Integer.parseInt(devserial);
		String model = request.getParameter("devmodel");
		String mdate = request.getParameter("devmdate");
		String edate = request.getParameter("devedate");
		String department = request.getParameter("devdepart");
		String producter = request.getParameter("devcomp");
		String extra = request.getParameter("remarks");
		String username=request.getParameter("devuser");
		userId= (int) ((User) request.getSession(true).getAttribute(
				"user")).getUserId();
		AddDevice test = new AddDevice();
		test.AddType(type, 1, 1, "̨台");
		if (test.AddNew(type, serial, model, department, producter, edate,
				mdate, extra,username)) {
			test.addRecord(userId,department);
			response.sendRedirect("listSB.jsp");
		}
	}

}
